﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Leo.Cloud.IdentityLogin.Dtos;
using Leo.Cloud.IdentityLogin.Localization;
using Leo.Cloud.IdentityLogin.Servcies;
using Swashbuckle.AspNetCore.Annotations;
using System.ComponentModel;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Users;

namespace Leo.Cloud.IdentityLogin.Controllers;

[Area(IdentityLoginServiceConsts.ModuleName)]
[RemoteService(Name = IdentityLoginServiceConsts.RemoteServiceName)]
[Route("api/identity-login")]
[SwaggerTag("用户登录管理模块")]
public class IdentityLoginController : AbpControllerBase
{
    private readonly IPassportService _passportService;
    private readonly ICurrentUser _currentUser;
    public IdentityLoginController(IPassportService passportService,
        ICurrentUser currentUser)
    {
        _passportService = passportService;
        _currentUser = currentUser;
    }

    [Authorize]
    [HttpGet("getcuruser")]
    [SwaggerOperation(Summary = "获取当前用户登录信息", Tags = new[] { "IdentityLogin" })]
    public ActionResult<dynamic> GetCurrentUserInfo()
    {
        var identity = _currentUser;
        return Ok(identity);
    }


    [HttpPost]
    [Route("login")]
    [SwaggerOperation(Summary = "用户登录接口", Tags = new[] { "IdentityLogin" })]
    public async Task<IdentityLoginOutput> Login([FromBody] IdentityLoginInput input)
    {
        return await _passportService.SignIn(input);    
    }

    [HttpPost]
    [Route("logout")]
    [SwaggerOperation(Summary = "用户登出接口", Tags = new[] { "IdentityLogin" })]
    public async Task<bool> Logout()
    {
        return await Task.FromResult(true);
    }
}
